.pragma library


function permissionLabel(val) {
    var n = parseInt(val);
    switch (n) {
    case 0: return "管理员";
    case 1: return "工艺员";
    case 2: return "审计员";
    case 3: return "操作员";
    default: return String(val);
    }
}

function validatePassword(passwordComplexity, passwordLength, password){
    if (password.length <　parseInt(passwordLength)){
        return "密码长度不能小于"+passwordLength+"位"
    }

    if (passwordComplexity === "complex"){
        const hasUpperCase = /[A-Z]/.test(password);
        const hasLowerCase = /[a-z]/.test(password);
        const hasNumber = /[0-9]/.test(password);
        const hasSpecialChar = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password);
        if(!(hasUpperCase && hasLowerCase && hasNumber && hasSpecialChar))
        {
            return "密码必须包含大写字母、小写字母、数字和特殊符号";
        }
    }
    return "";
}

function createModel(root){
    var mask = Qt.createQmlObject(`
        import QtQuick
        import QtQuick.Controls

        Rectangle {
            id: mask
            anchors.fill: parent
            color: "#00000000"
            z: 2

            // 点击遮罩关闭
            MouseArea {
                anchors.fill: parent
            }
            Behavior on color {
               ColorAnimation {
                   duration: 500
                   easing.type: Easing.InOutQuad
               }
            }
            Component.onCompleted: {
               color = "#80000000";
            }
        }`, root, "");
    return mask;
}

function secondsToHMS(seconds) {
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const secs = seconds % 60;

    // console.log("hhh", hours, minutes, secs, seconds)
    return [
        hours.toString().padStart(2, '0'),
        minutes.toString().padStart(2, '0'),
        secs.toString().padStart(2, '0')
    ].join(':');
}
